﻿// ===============================================================================
// NotNullRule.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Rules
{
    /// <summary>
    /// Verifies that the value is not null.
    /// </summary>
    public class NotNullRule : Rule
    {        
        /// <summary>
        /// Initializes a new instance of the <see cref="NotNullRule"/> class
        /// with a description
        /// </summary>
        /// <param name="brokenDescription">The description.</param>
        /// <exception cref="ArgumentNullException"><paramref name="brokenDescription"/> is
        /// null (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="brokenDescription"/> is a string
        /// of length 0 or contains only blanks.</exception>
        public NotNullRule(string brokenDescription)
            : base(brokenDescription)
        {
        }

        /// <summary>
        /// Validates that the rule has been followed.
        /// </summary>
        /// <param name="value">The value to validate.</param>
        /// <returns>
        /// <c>true</c>, if the value is valid, otherwise false.
        /// </returns>
        public override bool Validate(object value)
        {
            if (value != null)
            {
                return !string.IsNullOrEmpty(value.ToString());
            }
            return false;
        }
    }
}
